package entitynameisunique;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import entitynameisunique.EntityNameIsUniqueMatch;
import entitynameisunique.EntityNameIsUniqueMatcherFactory;
import entitynameisunique.EntityNameIsUniqueMatcher;

public class EntityNameIsUniqueConstraint extends Constraint<EntityNameIsUniqueMatch> {

	private EntityNameIsUniqueMatcherFactory matcherFactory;

	public EntityNameIsUniqueConstraint() {
		matcherFactory = new EntityNameIsUniqueMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "There are more than one entites with name $entity.name$. Entity names should be unique!";
	}

	@Override
	public EObject getLocationObject(EntityNameIsUniqueMatch signature) {
		Object location = signature.get("entity");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<EntityNameIsUniqueMatch, EntityNameIsUniqueMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
